<template>
  <div class="drinks-container">
    <div class="drinks-header">
      <div class="drinks-categories">
        <h2>精选酒水</h2>
        <el-radio-group v-model="currentCategory" size="medium">
          <el-radio-button label="all">全部</el-radio-button>
          <el-radio-button v-for="category in categories" :key="category" :label="category">
            {{ category }}
          </el-radio-button>
        </el-radio-group>
        <div class="category-description" v-if="currentCategory !== 'all'">
          <span>{{ getCategoryDescription(currentCategory) }}</span>
        </div>
      </div>
      <el-input
        placeholder="搜索酒水..."
        prefix-icon="el-icon-search"
        v-model="searchQuery"
        class="search-input"
      ></el-input>
    </div>

    <el-row :gutter="20">
      <el-col :span="24" v-for="drink in displayDrinks" :key="drink.id">
        <el-card :body-style="{ padding: '0px' }" class="drink-card" :class="{ 'adding': addingToCart === drink.id }">
          <div class="drink-content">
            <div class="drink-image-container">
              <img :src="drink.image" class="drink-image">
            </div>
            <div class="drink-info">
              <h3>{{ drink.name }}</h3>
              <p class="drink-description">{{ drink.description }}</p>
              <div class="drink-details">
                <span class="category-tag">{{ drink.category }}</span>
                <span class="volume">{{ drink.volume }}</span>
              </div>
            </div>
            <div class="drink-price-actions">
              <span class="price">¥{{ drink.price }}</span>
              <el-button 
                type="primary" 
                size="small"
                @click="addToCart(drink)"
                :loading="addingToCart === drink.id"
                class="add-cart-btn"
              >
                <i class="el-icon-shopping-cart-2"></i>
                <span>加入购物车</span>
              </el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'Drinks',
  data() {
    return {
      searchQuery: '',
      currentCategory: 'all',
      addingToCart: null,
      categoryDescriptions: {
        '白酒': '浓香醇厚，回味悠长',
        '红酒': '果香浓郁，口感细腻',
        '啤酒': '清爽怡人，解暑佳品',
        '饮料': '多种选择，解渴提神'
      }
    }
  },
  computed: {
    drinks() {
      return this.$store.state.drinks
    },
    categories() {
      return [...new Set(this.drinks.map(drink => drink.category))]
    },
    filteredDrinks() {
      if (!this.searchQuery) return this.drinks
      const query = this.searchQuery.toLowerCase()
      return this.drinks.filter(drink => 
        drink.name.toLowerCase().includes(query) ||
        drink.description.toLowerCase().includes(query)
      )
    },
    displayDrinks() {
      let drinks = this.filteredDrinks
      if (this.currentCategory !== 'all') {
        drinks = drinks.filter(drink => drink.category === this.currentCategory)
      }
      return drinks
    }
  },
  methods: {
    addToCart(drink) {
      this.addingToCart = drink.id
      this.$store.commit('addToCart', drink)
      this.$message({
        message: '已添加到购物车',
        type: 'success',
        duration: 2000,
        customClass: 'custom-message'
      })
      setTimeout(() => {
        this.addingToCart = null
      }, 300)
    },
    getCategoryDescription(category) {
      return this.categoryDescriptions[category] || ''
    }
  }
}
</script>

<style scoped>
.drinks-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%);
}

.drinks-header {
  margin-bottom: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drinks-categories {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.drinks-header h2 {
  font-size: 28px;
  color: #303133;
  margin: 0;
  font-weight: 600;
  background: linear-gradient(45deg, #409EFF, #36D1DC);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.search-input {
  width: 300px;
}

.drink-card {
  margin-bottom: 20px;
  transition: all 0.3s;
  border: none;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.drink-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
}

.drink-content {
  display: flex;
  align-items: center;
  padding: 16px;
}

.drink-image-container {
  width: 120px;
  height: 120px;
  overflow: hidden;
  position: relative;
  border-radius: 8px;
  flex-shrink: 0;
}

.drink-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s;
}

.drink-card:hover .drink-image {
  transform: scale(1.08);
}

.drink-info {
  flex: 1;
  margin: 0 20px;
}

.drink-price-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.category-tag {
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
}

.drink-details {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.drink-content h3 {
  margin: 0 0 8px;
  font-size: 18px;
  color: #303133;
}

.drink-description {
  color: #666;
  margin: 0 0 12px;
  height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: 14px;
  line-height: 1.4;
}

.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.price {
  font-size: 20px;
  color: #f56c6c;
  font-weight: bold;
}

.volume {
  font-size: 14px;
  color: #909399;
}

.add-cart-btn {
  background: linear-gradient(45deg, #409EFF, #36D1DC);
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.3s;
}

.add-cart-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(64,158,255,0.3);
}

.adding {
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media screen and (max-width: 768px) {
  .drinks-header {
    flex-direction: column;
    gap: 15px;
  }
  .search-input {
    width: 100%;
  }
  .el-radio-group {
    display: flex;
    overflow-x: auto;
    padding-bottom: 5px;
  }
}
</style> 